﻿<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="NotificationManager.aspx.cs" Inherits="WebProxy.NotificationManager" %>
<%@ Import Namespace="WebProxy" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<script language="c#" runat="server" >

protected void tbTimeFrom_SelectionChanged(object sender, EventArgs e)
{
    tbTimePicked.Value = tbTimeFrom.SelectedDate.ToString();
}
protected void rfTimeFrom_SelectionChanged(object sender, EventArgs e)
{
    rfTimePicked.Value = rfTimeFrom.SelectedDate.ToString(); 
   
}
protected void NotificationTable_Load(object sender, EventArgs e)
{
    string query = "Select * from Notification";
    SQLiteDatabase dataAdapter = new SQLiteDatabase();
    DataTable table = dataAdapter.GetDataTable(query);
    DataTable content = new DataTable();
    content.Clear();
    content.Columns.Add("Tytuł");
    content.Columns.Add("Wiadomość");
    content.Columns.Add("Link");
    content.Columns.Add("Dostępne od");
    content.Columns.Add("Dostępne do");
    int size = table.Rows.Count;
    for (int i = 0; i < size; i++)
    {
        DateTime avaFrom = new DateTime(Convert.ToInt64(table.Rows[i]["avaFrom"].ToString()));
        DateTime avaTo   = new DateTime(Convert.ToInt64(table.Rows[i]["avaTo"].ToString()));
        DataRow row = content.NewRow();
        row["Tytuł"] = table.Rows[i]["Title"].ToString();
        row["Wiadomość"] = table.Rows[i]["Message"].ToString();
        row["Link"] = table.Rows[i]["Uri"].ToString();
        row["Dostępne od"] = avaFrom.ToString();
        row["Dostępne do"] = avaTo.ToString();
        content.Rows.Add(row);
    }
    NotificationTable.DataSource = content;
    NotificationTable.DataBind();
}
protected void RefreshTable_Load(object sender, EventArgs e)
{
    string query = "Select * from RefreshTIme";
    SQLiteDatabase dataAdapter = new SQLiteDatabase();
    DataTable table = dataAdapter.GetDataTable(query);
    DataTable content = new DataTable();
    content.Clear();
    content.Columns.Add("Dostępne od");
    content.Columns.Add("Dostępne do");
    content.Columns.Add("Minuty");
    int size = table.Rows.Count;
    for (int i = 0; i < size; i++)
    {
        DateTime avaFrom = new DateTime(Convert.ToInt64(table.Rows[i]["avaFrom"].ToString()));
        DateTime avaTo = new DateTime(Convert.ToInt64(table.Rows[i]["avaTo"].ToString()));
        DataRow row = content.NewRow();
        row["Minuty"] = table.Rows[i]["Minutes"].ToString();
        row["Dostępne od"] = avaFrom.ToString();
        row["Dostępne do"] = avaTo.ToString();
        content.Rows.Add(row);
    }
    RefreshTable.DataSource = content;
    RefreshTable.DataBind();
}
protected void PathLoad(object sender, EventArgs e)
{
    
    path.Text = System.Web.HttpContext.Current.Server.MapPath("~/") + "database.db";
}
</script>
<body>
    <form id="form1" runat="server">
    <div style="margin-left: 40px">
    
        <strong>Manager notyfikacji</strong><br />
        <asp:TextBox ID="path" runat="server" OnLoad="PathLoad"></asp:TextBox>
        <br />
        Tytuł:<br />
        <asp:TextBox ID="tbTitle" runat="server" Enabled="true" ></asp:TextBox>
        <br />
        Treść:<br />
        <asp:TextBox ID="tbContent" runat="server"></asp:TextBox>
        <br />
        Link:<br />
        <asp:TextBox ID="tbLink" runat="server"></asp:TextBox>
        <br />
        Dostępne od:<br />
        <asp:Calendar ID="tbTimeFrom" runat="server" onselectionchanged="tbTimeFrom_SelectionChanged"></asp:Calendar>
        <br />
        <asp:HiddenField ID="tbTimePicked" runat="server"></asp:HiddenField>
        <br />
        <br />
        Czas ważności w minutach:<br />
        <asp:TextBox ID="tbLifeSpan" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Dodaj wiadomość" />
        <br />
        <br />
        <asp:GridView ID="NotificationTable" runat="server" OnLoad="NotificationTable_Load"></asp:GridView>
        <br />
        <br />
        </div>
        <div>
        <strong>Manager czasów odświerzania</strong>
        <br />
        <br />
        Data rozpoczęcia czasu odświerzania
        <asp:Calendar ID="rfTimeFrom" runat="server" OnSelectionChanged="rfTimeFrom_SelectionChanged"></asp:Calendar>
        <br />
        <asp:HiddenField ID="rfTimePicked" runat="server" />
        <br />
        Jak długo będzie ważny w minutach
        <br />
        <asp:TextBox ID="rfTimeSpan" runat="server"></asp:TextBox>
        <br />
        <br />
        Czas odświerzania w minutach
        <br />
        <asp:TextBox ID="rfRefreshValue" runat="server"></asp:TextBox>
            <br />
            <br />
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Dodaj czas odświerzania" /> 
            <br />
            <asp:GridView ID="RefreshTable" runat="server" OnLoad="RefreshTable_Load"></asp:GridView>
    </div>
    </form>
    
</body>
</html>
